/**
 * 
 */
package edu.pku.sei.modeler.uml.commands.activity;

import edu.pku.sei.modeler.commands.ModelCommand;
import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.uml.BasicActivities.ObjectFlow;
import edu.pku.sei.modeler.model.uml.FundamentalActivities.ActivityNode;
import edu.pku.sei.modeler.uml.commands.ConnectionModelCreateCommand;

/**
 * @author YanYan
 *
 */
class CreateObjectFlowCommand extends ConnectionModelCreateCommand {

	
	

	private ActivityNode src,des;
	private ObjectFlow objectFlow;
	
	public CreateObjectFlowCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel) {
		super(connectionModel, sourceModel);
		src = (ActivityNode) sourceModel;
		objectFlow = (ObjectFlow) connectionModel;
	}
	@Override
	public void setTarget(MetaModelElement target) {
		super.setTarget(target);
		if (target instanceof ActivityNode) {
			this.des = (ActivityNode)target;
		}
	}

	public boolean canExecute() {
		return true;
	}
	
	public void execute() {
		if(src != null){
			src.getOutgoing().add(objectFlow);
		}
		if(des != null){
			des.getIncoming().add(objectFlow);
		}
		if(objectFlow != null){
			objectFlow.setContainer(src);
			objectFlow.setModel(src.getModel());
		}
	}
	
	public void undo() {
		//TODO
	}
}
